package com.ruoyi.stock.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.stock.domain.StockTopBoard;
import com.ruoyi.stock.mapper.StockTopBoardMapper;
import com.ruoyi.stock.service.IStockTopBoardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 今日涨停个股Service业务层处理
 *
 * @author ruoyi
 * @date 2025-07-12
 */
@Service
public class StockTopBoardServiceImpl implements IStockTopBoardService {
    @Resource
    private StockTopBoardMapper stockTopBoardMapper;

    /**
     * 查询今日涨停个股
     *
     * @param id 今日涨停个股主键
     * @return 今日涨停个股
     */
    @Override
    public StockTopBoard selectStockTopBoardById(Long id) {
        return stockTopBoardMapper.selectStockTopBoardById(id);
    }

    /**
     * 查询今日涨停个股列表
     *
     * @param stockTopBoard 今日涨停个股
     * @return 今日涨停个股
     */
    @Override
    public List<StockTopBoard> selectStockTopBoardList(StockTopBoard stockTopBoard) {
        return stockTopBoardMapper.selectStockTopBoardList(stockTopBoard);
    }

    /**
     * 新增今日涨停个股
     *
     * @param stockTopBoard 今日涨停个股
     * @return 结果
     */
    @Override
    public int insertStockTopBoard(StockTopBoard stockTopBoard) {
        stockTopBoard.setCreateTime(DateUtils.getNowDate());
        return stockTopBoardMapper.insertStockTopBoard(stockTopBoard);
    }

    @Override
    public AjaxResult importData(List<StockTopBoard> list, boolean updateSupport) {
        if (list != null && list.size() > 0) {
            Date stDate = list.get(0).getStDate();
            stockTopBoardMapper.deleteStockTopBoardByDate(stDate);
            Date nowDate = DateUtils.getNowDate();
            for (StockTopBoard stockTopBoard : list) {
                stockTopBoard.setCreateTime(nowDate);
                stockTopBoardMapper.insertStockTopBoard(stockTopBoard);
            }
            //数据同步
            stockTopBoardMapper.syncMarketDate(stDate);
            return AjaxResult.success("导入成功,导入 "+list.size()+" 条数据 ！ ");

        }
        return AjaxResult.success("表中数据为空");
    }

    /**
     * 修改今日涨停个股
     *
     * @param stockTopBoard 今日涨停个股
     * @return 结果
     */
    @Override
    public int updateStockTopBoard(StockTopBoard stockTopBoard) {
        stockTopBoard.setUpdateTime(DateUtils.getNowDate());
        return stockTopBoardMapper.updateStockTopBoard(stockTopBoard);
    }

    /**
     * 批量删除今日涨停个股
     *
     * @param ids 需要删除的今日涨停个股主键
     * @return 结果
     */
    @Override
    public int deleteStockTopBoardByIds(Long[] ids) {
        return stockTopBoardMapper.deleteStockTopBoardByIds(ids);
    }

    /**
     * 删除今日涨停个股信息
     *
     * @param id 今日涨停个股主键
     * @return 结果
     */
    @Override
    public int deleteStockTopBoardById(Long id) {
        return stockTopBoardMapper.deleteStockTopBoardById(id);
    }
}
